/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package manager;

import entity.ConnectDB;
import entity.Rate;
import entity.Rates;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import marshall.GenXML;

/**
 *
 * @author tiz
 */
public class RateManager {
    public RateManager(){}

    public Rates getRatesDB() {
        try {
            Rates rList = new Rates();
            Rate rate = null;
            ConnectDB con = new ConnectDB();
            Connection connection = con.getCon();
            Statement stm = connection.createStatement();

//            String query = "SELECT * FROM Films WHERE Name like '%" + filmName + "%'";
            String query = "SELECT * FROM Rate";
            ResultSet rs = stm.executeQuery(query);
            while (rs.next()) {
                String filmID = rs.getString(1);
                int point = rs.getInt(2);
                rate = new Rate(filmID,point);
                rList.setRate(rate);
            }
            return rList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void ratesToXML(String filename) {
        RateManager rm = new RateManager();
        Rates rList = new Rates();
        rList = rm.getRatesDB();

        GenXML genxml = new GenXML();
        genxml.mar(rList, filename);
    }

}
